;;;;;;;;;;;;;;;;;;;;;;;;
; Google Chrome Fix    ;
; a WebReflection idea ;
; by Andrea Giammarchi ;
; -------------------- ;
; @date     2008/09/04 ;
; @license  Mit Style  ;
;;;;;;;;;;;;;;;;;;;;;;;;

#include <GUIConstantsEx.au3>

; Function Declaration
Func CloseApp()
	Exit
EndFunc

Func FixReg()
	RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SysPlant", "Start", "REG_DWORD", 0x00000004)
	If MsgBox(1, "Notice", "To apply changes you need to reboot your system." & @CRLF & "Do you want to reboot it now?") == 1 Then
		Shutdown(2)
	EndIf
EndFunc

Func GetGoogleDir($TEMP)
	RunWait(@ComSpec & " /c " & "dir Google /s /B > """ & $TEMP & "\_Google_Chrome_.txt""", $TEMP & "\..\", @SW_HIDE)
	Local	$GOOGLEDIR	= FileReadLine($TEMP & "\_Google_Chrome_.txt", 1)
	FileDelete($TEMP & "\_Google_Chrome_.txt")
	Return	$GOOGLEDIR
EndFunc

Func NoSand()
	Local	$FILE	= $APPDATA & "\Chrome\Application\chrome.exe"
	Local	$LNK	= EnvGet("USERPROFILE") & "\Desktop\Google Chrome No Sandbox.lnk"
	Local	$WORKDIR= $APPDATA & "\Chrome\Application"
	Local	$ARGS	= "--no-sandbox"
	Local	$DESC	= "Google Chrome No Sandbox"
	Local	$ICON	= $APPDATA & "\Chrome\Application\chrome.exe"
	Local	$HOTKEY	= ""
	Local	$INUMBER= 0
	Local	$STATE	= @SW_SHOWNORMAL
	FileCreateShortcut($FILE, $LNK, $WORKDIR, $ARGS, $DESC, $ICON, $HOTKEY, $INUMBER, $STATE)
EndFunc

; GUI Application
AutoItSetOption("TrayIconHide", 1)
Opt("GUIOnEventMode", 1)
$MAIN		= GUICreate("Google Chrome Fix", 200, 85)
$REG_BTN	= GUICtrlCreateButton("Fix Registry Related Problem", 5, 5, 190)
$NOS_BTN	= GUICtrlCreateButton("Create A No Sandbox Link", 5, 35, 190)
$LABEL		= GUICtrlCreateLabel("a webreflection.blogspot.com idea", 5, 65, 190)
$APPDATA	= GetGoogleDir(EnvGet("TEMP"))
GUICtrlSetColor($LABEL, 0x555555)
GUICtrlSetStyle($LABEL, 0x01)
GUICtrlSetOnEvent($REG_BTN, "FixReg")
GUICtrlSetOnEvent($NOS_BTN, "NoSand")
GUISetOnEvent($GUI_EVENT_CLOSE, "CloseApp")
GUISetState(@SW_SHOW)

; System Checks
If RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SysPlant", "Start") == "" Then
	GUICtrlSetState($REG_BTN, $GUI_DISABLE)
EndIf
If @error Then
	GUICtrlSetState($NOS_BTN, $GUI_DISABLE)
EndIf

; Program Execution
While 1
  Sleep(1000)
WEnd